open String

let compare a b = if a>b then 1
		  else if a=b then 0 
			      else -1;;

(*
let rec find name list = let name2=lowercase name in
 match list with
	|[] -> failwith "unused name"
	|(n,x)::l -> if n=name2 then x 
               else find l;;
*)

let rec add ("name",x) l = match l with
	|[] -> []
	|(n,_)::liste when n="name" -> (n,x)::add ("name",x) liste
	|(n,y)::liste when n<"name" -> ("name",x)::(n,y)::add ("name",x) liste
	|(n,_)::liste when n>"name" -> (lowercase "name",x)::l;;


(*
let rec delete "name" l = match l with
	|[] -> []
	|(n,_)::liste when n="name" -> (n,x)::delete ("name",x) liste
	|(n,_)::liste -> delete ("name",x) liste;;
*)

let rec update "name" x l = match l with
	|[] -> []
	|(n,_)::liste when n="name" -> (n,x)::liste
	|(n,y)::liste -> (n,y)::update "name" x liste;;

(*
let name "name1" "name2" l = let y=find "name1" l in
	let l2 = delete "name1" l in
	add ("name2",y) l2;;

let rec map f liste = match liste with
	|[] -> []
	|e::l -> f e::map l;;

let sales l s = 
    let f x = function (n,x) -> (n,x-(s/100)*x) in 
		map f l;;
*)
